import { observable, action, makeObservable } from "mobx";
import { PageDateSelect } from '@/types/pages/enum'
import {IStore} from  '@/types/pages/base'
import { ICustomerFull } from "@/types/pages/customer/interface";
import { getColumnChart, getLineChart, getPieLeftChart,getPieRightChart, getSaleInfoContractData, getSaleInfoCustomerData, getSaleInfoMoneyData } from "@/api/customer";


/**
 * class Customer
 * 客户分析
 */
class Customer implements IStore<ICustomerFull> {
    @observable screenData: ICustomerFull= {saleInfoCustomer:{},saleInfoMoney:{},saleInfoContract:{},
      pieLeftChart:{},pieRightChart:{},lineChart:{},columnChart:{}}

    constructor() {
      makeObservable(this)
  }
   /**
     *
     * @param type 日期选择函数
     * @param date 传入日期
     */
     @action async getScreenData(type: PageDateSelect,date?:Date) {

        // 获取左上部分
        this.screenData.saleInfoCustomer= await getSaleInfoCustomerData(type,date);
        this.screenData.saleInfoMoney= await getSaleInfoMoneyData(type,date);
        this.screenData.saleInfoContract= await getSaleInfoContractData(type,date);
        this.screenData.pieLeftChart= await getPieLeftChart(type,date);
        this.screenData.pieRightChart= await getPieRightChart(type,date);
        this.screenData.lineChart= await getLineChart(type,date);
        this.screenData.columnChart=await  getColumnChart(type,date);
        return  this.screenData;
    }

    @action async setLineChartData(type: PageDateSelect,date?:Date) {

      this.screenData.lineChart= await getLineChart(type,date);

      return  this.screenData.lineChart;
  }


}
export default Customer;
